define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'manystore/banji/index' + location.search,
                    add_url: 'manystore/banji/add',
                    edit_url: 'manystore/banji/edit',
                    del_url: 'manystore/banji/del',
                    multi_url: 'manystore/banji/multi',
                    import_url: 'manystore/banji/import',
                    table: 'manystore_banji',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shop.name', title: __('Shop.name'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'weigh', title: __('Weigh'), operate: false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons: [
                                {
                                    name: 'banji',
                                    text: __('老师列表'),
                                    title: __('老师列表'),
                                    classname: 'btn btn-xs btn-success btn-primary btn-dialog btn-area-big',
                                    extend: 'data-area=\'["95%", "95%"]\'',
                                    icon: 'fa',
                                    url: function(row){
                                        let _url = Config.moduleurl + '/manystore/teacher?banji_id='+row.id;
                                        // let _url = Config.moduleurl + '/myadmin/camera?company_id='+row.id;
                                        return _url;
                                    },
                                    visible: function (row) {
                                        return true;
                                    }
                                },
                                // {
                                //     name: 'banji',
                                //     text: __('家长列表'),
                                //     title: __('家长列表'),
                                //     classname: 'btn btn-xs btn-success btn-primary btn-dialog btn-area-big',
                                //     extend: 'data-area=\'["95%", "95%"]\'',
                                //     icon: 'fa',
                                //     url: function(row){
                                //         let _url = Config.moduleurl + '/manystore/monitor?shop_id='+row.id;
                                //         // let _url = Config.moduleurl + '/myadmin/camera?company_id='+row.id;
                                //         return _url;
                                //     },
                                //     visible: function (row) {
                                //         return true;
                                //     }
                                // },
                                {
                                    name: 'banji',
                                    text: __('学生列表'),
                                    title: __('学生列表'),
                                    classname: 'btn btn-xs btn-success btn-primary btn-dialog btn-area-big',
                                    extend: 'data-area=\'["95%", "95%"]\'',
                                    icon: 'fa',
                                    url: function(row){
                                        let _url = Config.moduleurl + '/manystore/student/index?banji_id='+row.id;
                                        return _url;
                                    },
                                    visible: function (row) {
                                        return true;
                                    }
                                },
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'manystore/banji/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'manystore/banji/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'manystore/banji/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            $("#c-monitor_id").data("eSelect", function(){
                //监控到的后续操作
                var monitor_id = $("#c-monitor_id").val();
                //异步查询第2个下拉的数据集
                $.post('ajax/monitorinfo',{monitor_id:monitor_id},function (res) {
                    //设置SelectPage数据
                    $('#c-monitor_info_ids').selectPageData(res.data);//这是第2个下拉
                    //刷新SelectPage
                    $('#c-monitor_info_ids').selectPageRefresh();
                },'json');
            });
            Controller.api.bindevent();
        },
        edit: function () {
            var monitor_id = $("#c-monitor_id").val();
            $.post('ajax/monitorinfo',{monitor_id:monitor_id},function (res) {
                //设置SelectPage数据
                $('#c-monitor_info_ids').selectPageData(res.data);//这是第2个下拉
                //刷新SelectPage
                var monitor_info_ids = $("#monitor_info_ids").val();
                console.log('monitor_info_ids',monitor_info_ids);
                $('#c-monitor_info_ids').val(monitor_info_ids);
                $('#c-monitor_info_ids').selectPageRefresh();
            },'json');

            $("#c-monitor_id").data("eSelect", function(){
                    //监控到的后续操作
                    var monitor_id = $("#c-monitor_id").val();
                    //异步查询第2个下拉的数据集
                    $.post('ajax/monitorinfo',{monitor_id:monitor_id},function (res) {
                        //设置SelectPage数据
                        $('#c-monitor_info_ids').selectPageData(res.data);//这是第2个下拉
                        //刷新SelectPage
                        $('#c-monitor_info_ids').selectPageRefresh();
                    },'json');
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
